package com.quicksignin.controller;

import com.quicksignin.common.Base64;
import com.quicksignin.common.ServerResponse;
import com.quicksignin.pojo.SignIn;
import com.quicksignin.service.ISignInService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

/**
 * Created by GHD on 2018/9/28.
 */
@Controller
@RequestMapping("")
public class SignInController {

    @Autowired
    ISignInService iSignInService;

    //跳转到签到页面
    @RequestMapping(value = "/signIn",method = RequestMethod.GET)
    public String showSignIn() {
//        System.out.println(teacherName);
//
////        User teacher = (User) session.getAttribute(Const.CURRENT_USER);
////        System.out.println(teacher.getTeacherName());
////        String teacherName = teacher.getTeacherName();
//        if (teacherName == null){
//            return "404";
//        }
        System.out.println("展示签到页面");
        return "signIn";
    }





    //进行签到
    @RequestMapping(value = "/signInOf",method = RequestMethod.POST)
    @ResponseBody
    public ServerResponse<SignIn> SignIn(String stuId, String name,final HttpServletRequest request,String teacherName)throws Exception {
        String ip = request.getRemoteAddr();

//        User teacher = (User) session.getAttribute(Const.CURRENT_USER);

//        String teacherName = teacher.getTeacherName();
        System.out.println(teacherName);
        ServerResponse<SignIn> response = iSignInService.signIn(stuId,name,ip, Base64.getFromBase64(teacherName));
        System.out.println("签到信息：学号："+stuId+"姓名："+name+",ip地址："+ip+",教师名字："+teacherName);
        return response;
    }


}
